<div class="reports">
  <div class="content_middle">

    <div class="report_content_header">
      <div class="report_content_heading">
        <h1><%= t('views.reports.revenue_by_client') %></h1>
      </div>

      <div class="content_header_data">
        <div class="header_data_left">
          <div class="header_data_detail">
            <ul>
              <li class="header_name"><%= @report.client_name %></li>
              <li class="header_duration"><%= @report.period %></li>
            </ul>
          </div>
        </div>
      </div>
      <!-- content_header_data -->
    </div>
    <!-- report_content_header -->

    <%= render 'reports/report_partials/format_links'%>

    <div class="revenue_by_client">
      <div class="grid_table">
        <table cellpadding="0" cellspacing="0" class="table_listing client_report_listing <%= I18n.locale %>">
          <colgroup>
            <col class="one"/>
            <col class="two"/>
            <col class="three"/>
            <col class="four"/>
            <col class="five"/>
          </colgroup>

          <thead>
            <th class="align_left"><%= t('views.clients.client') %></th>
            <% (@report.report_criteria.from_month..@report.report_criteria.to_month).each  do |month| %>
                <th class="align_right"><%= Date::MONTHNAMES[month].to_s[0..2] %></th>
            <% end %>
            <th class="align_right"><%= t('views.common.total') %></th>
          </thead>
          <tbody>
          <% unless @report.report_data.blank? %>
            <% @report.report_data.group_by{|data| data.organization_name}.values.each do |revenues| %>
              <tr>
                <td class="align_left text-overflow-class" data-sort_val="<%= revenues.first.organization_name %>"><%= revenues.first.organization_name %></td>
                <% (@report.report_criteria.from_month..@report.report_criteria.to_month).each do |month| %>
                  <td class="align_right" data-sort_val="<%= revenues.sum{|revenue| revenue["#{Date::MONTHNAMES[month]}"] } %>" >
                    <% revenues.each do |revenue| %>
                      <%= number_to_currency(revenue["#{Date::MONTHNAMES[month]}"],unit: revenue['currency_code']) %>
                      <br>
                    <% end %>
                  </td>
                <% end %>
                <td class="align_right" data-sort_val="<%= revenues.sum{|revenue| revenue.client_total } %>" >
                  <% revenues.each do |revenue| %>
                    <%= number_to_currency(revenue.client_total,unit: revenue['currency_code']) %>
                    <br>
                  <% end %>
                </td>
              </tr>
            <% end %>
            <tfoot>
              <tr>
                <td class="align_left"><%= t("views.common.total")%></td>
                <% (@report.report_criteria.from_month..@report.report_criteria.to_month).each do |month| %>
                    <td class="align_right">
                      <% @report.report_total.each do |total| %>
                        <%= total["#{Date::MONTHNAMES[month]}"] == 0 ? "" : number_to_currency(total["#{Date::MONTHNAMES[month]}"],unit: total[:currency_code])  %>
                        <br>
                      <% end %>
                    </td>
                <% end %>
                <td class="align_right">
                  <% @report.report_total.each do |total| %>
                    <%= number_to_currency(total[:net_total] || 0 , unit: total[:currency_code]) %>
                    <br>
                  <% end %>
                </td>
              </tr>
            </tfoot>
          <% else %>
            <tr>
              <td colspan="<%= 2+(@report.report_criteria.from_month..@report.report_criteria.to_month).size %>">
                <%= t('views.reports.report_no_data') %>
              </td>
            </tr>
          <% end %>
          </tbody>
        </table>
      </div>
      <!--grid_table-->
    </div>
    <!--revnue_by_client-->


    <div class="content_bottom">
      <div class="report_footer">

      </div>
      <!-- report_footer -->
    </div>
    <!--content_bottom-->

  </div>
  <!--content_middle-->
</div><!--reports-->